<?php
	//分享接口 share.php
	//create by L
	//http://42.121.57.193:7788/platform/share.php?phone=13000311130


	//初始化--
	include_once "init.php";

	$phone        	= $_GET["phone"];

	if('' == $phone )
	{
		die("-1|UID不可以为空");
	}
	if (strlen($phone) != 11 || false==is_numeric($phone) || ord($phone)!=49)
	{
		die("-1|手机号码必须是11位数字，并且以1开头");
	}

	$md5_phone 		= md5($phone);
	$share_time 	= date('Y-m-d H:i:s');
	$flag			= 0;

	$con = db_connect(DB_NAME);

	//号码是否存在
	$result = mysql_query("SELECT * from share where phone='$phone'") or die("-1|查询数据库失败");
	$row = mysql_fetch_row($result);

	if (empty($row))
	{
		//直接插入share表
		mysql_query("LOCK TABLES share WRITE");
		$result = mysql_query("INSERT INTO share (phone,md5_phone,share_time,flag) VALUES ('".$phone."','".$md5_phone."','".$share_time."','".$flag."')");
		mysql_query("UNLOCK TABLES");
	}
	else
	{
		//判断分享时间是否超过24小时，超过则插入，不超过不处理
		$db_share_time = $row['2'];
		$hours = intval((time() - strtotime($db_share_time)) / 3600);

		if ($hours >24)
		{
			mysql_query("LOCK TABLES share WRITE");
			$result = mysql_query("INSERT INTO share (phone,md5_phone,share_time,flag) VALUES ('".$phone."','".$md5_phone."','".$share_time."','".$flag."')");
			mysql_query("UNLOCK TABLES");
		}
		else
		{
			mysql_close($con);
			die("-1|24小时内只能分享一次");
		}
	}
	mysql_close($con);
	echo '0|';

?>
